package miggy;

import junit.framework.TestCase;
import miggy.api.config.ConfigurationException;
import miggy.api.cpu.Size;
import miggy.cpu.MC68000;
import miggy.memory.TestMem;

// $Revision: 21 $
public class BasicSetup extends TestCase
{
	protected int codebase;

	public BasicSetup(String test)
	{
		super(test);
	}

	@Override protected void setUp()
	{
		MC68000 cpu = new MC68000();

		try
		{
			cpu.init(null);
		}
		catch(ConfigurationException e)
		{
			//
		}

		SystemModel.CPU = cpu;

		SystemModel.MEM = TestMem.create(2048);

		//test vectors just containing the vector number
		for(int v = 0; v < 256; v++)
		{
			int addr = v << 2;
			//test: changed to poke
			SystemModel.MEM.poke(addr, v, Size.Long);
		}

		SystemModel.CPU.setAddrRegister(7, 2048);	//set up the stack
		SystemModel.CPU.setUSP(0x0800);
		SystemModel.CPU.setSSP(0x0780);
		codebase = 0x0400;
		SystemModel.CPU.setPC(codebase);
	}

	protected void setInstruction(int opcode)
	{
		SystemModel.MEM.poke(codebase, opcode, Size.Word);
	}

	protected void setInstructionParamW(int opcode, int param)
	{
		SystemModel.MEM.poke(codebase, opcode, Size.Word);
		SystemModel.MEM.poke(codebase + 2, param, Size.Word);
	}

	protected void setInstructionParamL(int opcode, int param)
	{
		SystemModel.MEM.poke(codebase, opcode, Size.Word);
		SystemModel.MEM.poke(codebase + 2, param, Size.Long);
	}

	@Override protected void tearDown()
	{
		SystemModel.CPU = null;
		SystemModel.MEM = null;
	}
}
